package kr.hkit.powerjava.chapter22.work2.dao;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

import kr.hkit.powerjava.chapter22.work2.vo.Department;
import kr.hkit.powerjava.chapter22.work2.vo.Student;

public class DepartmentManagerImpl implements ItemDaoInterface<Department> {
	private ArrayList<Department> arList;

	public DepartmentManagerImpl(ArrayList<Department> arList) {
		this.arList = arList;
	}

	@Override
	public void addItem(Department item) {
		
		arList.add(item);

	}

	@Override
	public void delItem(Department item) {
		arList.remove(item);

	}

	@Override
	public void updateItem(Department item) {
		if (searchItem(item)) {
			arList.set(arList.indexOf(item), item);
		} else {
			System.out.println("수정 실패");
		}

	}

	@Override
	public boolean searchItem(Department item) {
		return arList.contains(item);
	}

	@Override
	public void prnItems() {
		prnHeader();
		for (Department s : arList) {
			System.out.println(s);
		}
		System.out.println();

	}

	private void prnHeader() {
		String str = String.format("%3s\t%4s\t%3s", "학과번호", "학과명", "위치");
		System.out.println(str);
		System.out
				.println("---------------------------------------------------------");

	}

	@Override
	public void pinItems(Comparator<Department> comp) {
		Collections.sort(arList, comp);
		/* prnHeader(); */
		prnItems();
	}

}
